package com.example;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2022/3/3 10:31
 */
@RestController
public class IndexController {
    @Autowired
    StringRedisTemplate redisTemplate;

    @RequestMapping(value = "/sentinel_test")
    public void test() throws Exception {
        int i = 0;
        while (true) {
            String key = "liyuhang" + i;
            redisTemplate.opsForValue().set(key, "i=" + i, 20000, TimeUnit.SECONDS);
            i++;
            System.out.println("设置缓存：" + key + " , 当前次数：" + i);
            Thread.sleep(1000L);
        }
    }
}
